\name{xeno.nlmer.draw.data}
\alias{xeno.nlmer.draw.data}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Non-linear (nlmer) function for drawing data from a fitted object's frame
}
\description{
%%  ~~ A concise (1-5 lines) description of what the function does. ~~
}
\usage{
xeno.nlmer.draw.data(orig_data, responsename = "Response", idname = "Tumor_id", 
tpname = "Timepoint", maintitle = "Data", ymax = NULL)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{orig_data}{
The original data.frame used in the fitting of the mixed-effects model.
}
  \item{responsename}{
Column name with the response values in the data.frame. Defaults to "Response".
}
  \item{idname}{
Column name with the individual tumor or animal labels in the data.frame. Defaults to "Tumor_id".
}
  \item{tpname}{
Column name with the time points in the data.frame. Defaults to "Timepoint".
}
  \item{maintitle}{
Text title for the figure.
}
  \item{ymax}{
A cutoff point for y-axis not derived from the data.
}
}
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
%%  ~Describe the value returned
%%  If it is a LIST, use
%%  \item{comp1 }{Description of 'comp1'}
%%  \item{comp2 }{Description of 'comp2'}
%% ...
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
Teemu D Laajala <tlaajala@cc.hut.fi>
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
# MCF-7 LAR low dosage example dataset
data(mcf_low)

# Concept of fitting a non-linear model with the presented EM-algorithm procedure
# Defining a model with Michaelis-Menten kinetics. 
# Allowing random parameters of the M-M with the addition of an intercept 
#term that ought to catch the starting criteria
Model = function(Intercept, Offset, Treatment, Growth, VM, K, Timepoint) { 
	Intercept + Offset*Treatment + (Growth*VM*Timepoint/(K+Timepoint))
}
ModelGradient = deriv(body(Model)[[2]], namevec = c("Intercept", "Offset", "VM","K"), 
function.arg=Model)
starting_conditions = c(Intercept=20, Offset=-1, VM=100, K = 1)



nlmer_EM = xeno.nlmer.EM(
	formula = Response ~ ModelGradient(Intercept, Offset, Treatment, Growth, 
	VM, K, Timepoint) ~ (VM+K+Intercept|Tumor_id),
	data=mcf_low, 
	Model=Model, 
	ModelGradient=ModelGradient,
	start=starting_conditions, 
	verbose=TRUE,
	max.iter=10)

nlmer_fit = nlmer(Response ~ ModelGradient(Intercept, Offset, Treatment, Growth, 
VM, K, Timepoint) ~ (VM+K+Intercept|Tumor_id), data = nlmer_EM, 
start=starting_conditions)

par(mfrow=c(2,2))
xeno.nlmer.draw.data(mcf_low)
xeno.nlmer.draw.fixed(nlmer_fit,mcf_low, Model=Model)
xeno.nlmer.draw.fit(nlmer_fit, mcf_low)
xeno.nlmer.draw.res(nlmer_fit)

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ ~kwd1 }
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
